
import xml.dom.minidom

#####################################################################################################################################
# Artist class
class Artist:
	def __init__(self,node):
		self.ID = node.getAttribute('id')
		score = node.getAttribute('ext:score')
		if len(score) > 0:
			self.score = int(score)
		else:
			self.score = 100
		self.disambiguation = ''
		
		for n in node.getElementsByTagName('name')[0].childNodes:
			if n.nodeType == n.TEXT_NODE:
				self.name = n.data.strip()
		if len(node.getElementsByTagName('disambiguation')) > 0:
			for n in node.getElementsByTagName('disambiguation')[0].childNodes:
				if n.nodeType == n.TEXT_NODE:
					self.disambiguation = n.data.strip()
					self.display_name = self.name + ' (' + self.disambiguation + ')'
		else:
			self.display_name = self.name

	def compare(self,artist=None):
		if artist is None: return self
		if self.score > artist.score:
			return self
		else:
			return artist
		
	def __str__(self):
		s = ''
		s = s + 'score: '+ str(self.score) + '\n'
		s = s + 'ID: '+ str(self.ID) + '\n'
		s = s + 'Name: '+ str(self.name)
		return s
